// pages/find_info/index.js
var t = getApp(),
  e = t.requirejs("api/index"),
  core = t.requirejs("core"),
  wxParse = t.requirejs("wxParse/wxParse");
Page({
  data: {
    route: "find_info",
    menu: t.tabBar,
    menu_show: false,
    show: false,
    use_wxParse:true,
  },
  //底部导航跳转
  menu_url: function (k) {
    core.menu_url(k, 2);
  },
  onLoad: function (options) {

    if (options != null && options != undefined) {
      this.setData({
        tabbar_index: options.tabbar_index ? options.tabbar_index : -1
      });
    }

    core.setting();
    this.setData({
      menu: getApp().tabBar
    })
    var key = t.isInArray(getApp().tabBar.list, this.data.route);
    if (key) {
      this.setData({
        menu_show: true
      })

    }

    if (this.data.tabbar_index >= 0) {
      this.setData({
        showtabbar: true,
      })
    }

    var a = this;
    a.setData({
      id: options.id
    })

    this.getinfo();
  },

  getinfo:function(){

    var a = this,
      id = a.data.id;

    var e = {};
    core.get("product/product_info", {
      id: id,
    }, function (t) {
      wx.setNavigationBarTitle({
        title: t.info.title ? decodeURIComponent(t.info.title) : '产品详情'
      })
      if (t.code == 0) {
        try {
          wxParse.wxParse("wxParseData", "html", t.info.content, a, "0");
          e.use_wxParse = true;
          console.log("use wxParse !!!");
        }
        catch (err) {
          e.use_wxParse = false;
          console.log("not use wxParse !!!");
        }

        e.detail = t.info;
        e.show = true;
        a.setData(e)
      } else {
        core.alert(t.msg)
      }
    }, true)

  },

  onShow: function () {
    
  },
  /**
* 下拉刷新
*/
  onPullDownRefresh: function () {
    this.getinfo();
    wx.stopPullDownRefresh();
  },
  //分享
  onShareAppMessage: function () {
    var title = this.data.detail.title;
    var path = '/yb_shop/pages/product/info/index?id=' + this.data.detail.id;
    return {
      title: title,
      path: path
    }
  },
})